package fr.uparis10.miage.m1p1.menu.employe;

import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import fr.uparis10.miage.m1p1.config.Configurator;
import fr.uparis10.miage.m1p1.core.Employe;
import fr.uparis10.miage.m1p1.global.LogFactory;
import fr.uparis10.miage.m1p1.menu.MenuExecutor;

public class SearchEmployeExecutor implements MenuExecutor {
	private Logger log = LogFactory.getInstance().getLogger(
			ShowEmployeExecutor.class.getName());

	public void execute() {
		// TODO ask the some employee data and search it in the organization
		byte[] buf = new byte[100];
		System.out.print("Employee Name?: ");
		String emplName;
		while (true) {
			try {
				System.in.read(buf);
				emplName = (new String(buf)).trim();
			} catch (IOException exc) {
				log.log(Level.SEVERE, "Ooops...", exc);
				return;
			} catch (NumberFormatException exc) {
				log.log(Level.WARNING, "Invalid number", exc);
				continue;
			}
			break;
		}
//		ObjectJ entr = Configurator.getInstance().getObjectJ();
		// TODO: change this logic to get everything from ObjectJ
//		Employe empl = Configurator.getInstance().getEmployeMap().get(employeId);
		ArrayList<Employe> emplList = Configurator.getInstance().getEmployeListe();
		for (Employe empl: emplList) {
			if (empl.getNom().equals(emplName)) {
				System.out.println(empl);
		
			}
		}

	}

}
